package Web.ManagedBeans;
import java.io.Serializable;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.ViewScoped;
import model.Entity.SIS.AcademicCalendar;
import model.Entity.SIS.Semester;
import model.Entity.SIS.StudyType;
import model.Service.AcademicCalendarService;
import model.Service.SemesterService;
import model.Service.StudyTypeService;

@ManagedBean(name="academicCalendarMB")
@ViewScoped
public class academicCalendarMB implements Serializable {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	//private static final long serialVersionUID = 1L;
	private List<AcademicCalendar> entitiesList;
	private AcademicCalendar entity;
	private StudyType studyTypeEntity;
	private List<StudyType> studyTypeList;
	private List<Semester> semesterList;
	private Semester semesterEntity;
	private int studyCode;
	private int semester;
	
	
	@ManagedProperty(value="#{AcademicCalendarService}")
	private AcademicCalendarService service;
	
	@ManagedProperty(value="#{StudyTypeService}")
	private StudyTypeService studyService;
	
	@ManagedProperty(value="#{SemesterService}")
	private SemesterService semesterService;
	
	@PostConstruct
	public void init(){
		System.out.println("inside*****init*********");
		setEntitiesList(getService().getAllAcademicCalendar());
		setStudyTypeList(getStudyService().getAll());
		setSemesterList(getSemesterService().getActiveSemesters());
		
	}
	
	public void refreshAcademicCalendar(){
		if(studyCode == 0 && semester == 0){
			setEntitiesList(getService().getAllAcademicCalendar());
		}else if(studyCode != 0 && semester == 0){
			
		}
	}


	public List<AcademicCalendar> getEntitiesList() {
		//System.out.println("inside getEntitiesList ***********************");
		if(entitiesList == null)
			entitiesList = getService().getAllAcademicCalendar();
		return entitiesList;
	}


	public void setEntitiesList(List<AcademicCalendar> entitiesList) {
		this.entitiesList = entitiesList;
	}


	public AcademicCalendar getEntity() {
		return entity;
	}


	public void setEntity(AcademicCalendar entity) {
		this.entity = entity;
	}


	public AcademicCalendarService getService() {
		return service;
	}


	public void setService(AcademicCalendarService service) {
		this.service = service;
	}
	
	public List<AcademicCalendar> getCalendarBySemester(int semester){
		return service.findBySemester(semester);
	}
	
	public List<AcademicCalendar> getCalendarByStudyCode(int studyCode){
		return service.findByStudyCode(studyCode);
	}
	
	public List<AcademicCalendar> getCalendarBySemesterStudyCode(int semester, int studyCode){
		return service.findBySemesterAndStudyCode(semester, studyCode);
	}


	public StudyTypeService getStudyService() {
		return studyService;
	}


	public void setStudyService(StudyTypeService studyService) {
		this.studyService = studyService;
	}


	public StudyType getStudyTypeEntity() {
		return studyTypeEntity;
	}


	public void setStudyTypeEntity(StudyType studyTypeEntity) {
		this.studyTypeEntity = studyTypeEntity;
	}


	public List<StudyType> getStudyTypeList() {
		return studyTypeList;
	}


	public void setStudyTypeList(List<StudyType> studyTypeList) {
		this.studyTypeList = studyTypeList;
	}


	public List<Semester> getSemesterList() {
		return semesterList;
	}


	public void setSemesterList(List<Semester> semesterList) {
		this.semesterList = semesterList;
	}


	public SemesterService getSemesterService() {
		return semesterService;
	}


	public void setSemesterService(SemesterService semesterService) {
		this.semesterService = semesterService;
	}


	public Semester getSemesterEntity() {
		return semesterEntity;
	}


	public void setSemesterEntity(Semester semesterEntity) {
		this.semesterEntity = semesterEntity;
	}

	public int getStudyCode() {
		return studyCode;
	}

	public void setStudyCode(int studyCode) {
		this.studyCode = studyCode;
	}

	public int getSemester() {
		return this.semester;
	}

	public void setSemester(int semester) {
		this.semester = semester;
	}
	
}
